home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / AvantBrowser / asetup.exe / _data / webkit / chrome_100_percent.pak / Unnamed File 000041.txt < prev    next >
Text File  |  2013-04-03  |  1KB  |  48 lines

  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4.  
  5. // Custom bindings for the runtime API.
  6.  
  7. var runtimeNatives = requireNative('runtime');
  8. var extensionNatives = requireNative('extension');
  9. var GetExtensionViews = extensionNatives.GetExtensionViews;
  10. var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
  11.  
  12. chromeHidden.registerCustomHook('runtime', function(bindings, id, contextType) {
  13.   var apiFunctions = bindings.apiFunctions;
  14.  
  15.   //
  16.   // Unprivileged APIs.
  17.   //
  18.  
  19.   chrome.runtime.id = id;
  20.  
  21.   apiFunctions.setHandleRequest('getManifest', function() {
  22.     return runtimeNatives.GetManifest();
  23.   });
  24.  
  25.   apiFunctions.setHandleRequest('getURL', function(path) {
  26.     path = String(path);
  27.     if (!path.length || path[0] != '/')
  28.       path = '/' + path;
  29.     return 'chrome-extension://' + id + path;
  30.   });
  31.  
  32.   //
  33.   // Privileged APIs.
  34.   //
  35.   if (contextType != 'BLESSED_EXTENSION')
  36.     return;
  37.  
  38.   apiFunctions.setCustomCallback('getBackgroundPage',
  39.                                  function(name, request, response) {
  40.     if (request.callback) {
  41.       var bg = GetExtensionViews(-1, 'BACKGROUND')[0] || null;
  42.       request.callback(bg);
  43.     }
  44.     request.callback = null;
  45.   });
  46.  
  47. });
  48.